package com.noanao;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class demo {
    public static int i = 0;
    public static void main(String[] args) {
        final Lock lock=new ReentrantLock();
        System.out.println("第一次修改啊");
        System.out.println("第二次添加");
        Thread a=new Thread(new Runnable() {
            @Override
            public  void run() {
                while (true){
                    lock.lock();
                    if (i%3==0){
                        System.out.print("a");
                        i++;
                    }
                    lock.unlock();
                }
            }
        });
        Thread b=new Thread(new Runnable() {
            @Override
            public  void run() {
                while (true){
                    lock.lock();
                    if (i%3==1){
                        System.out.print("b");
                        i++;
                    }
                    lock.unlock();
                }
            }
        });
        Thread c=new Thread(new Runnable() {
            @Override
            public  void run() {
                while (true){
                    lock.lock();
                    if (i%3==2){
                        System.out.print("c");
                        i++;
                    }
                    lock.unlock();
                }
            }
        });
        a.start();
        b.start();
        c.start();
    }
}
